<!DOCTYPE html>
<html class="x-admin-sm">
    <head>
        <meta charset="UTF-8">
        <title>动物认知列表</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="./css/font.css">
        <link rel="stylesheet" href="./css/xadmin.css">
        <script src="./lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="./js/xadmin.js"></script>
        <style type="text/css">
          .layui-table-cell{
              height: auto!important;
              white-space: normal;
          }
  </style>

    </head>
    <body>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-header">
                            <button class="layui-btn" onclick="xadmin.open('添加水果','./fruit-add.html',600,400)"><i class="layui-icon"></i>添加新内容</button>
                            <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
                              <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
                          </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                          <table class="layui-table" lay-data="{height:315, url:'https://api.lzjlw.top:3030/backstage/fruit_Cognize',parseData:function(res){return{'code':0,'data':res,'count':20}} ,page:true, id:'videoinfo'}" lay-filter="videoinfo">
                            <thead>
                              <tr>
                                <th lay-data="{field:'id', width:90,align:'center', sort: true}">ID</th>
                                <th lay-data="{field:'cognizeId',align:'center', width:150}">认知ID</th>
                                <th lay-data="{field:'Cname',align:'center',width:150 }">中文形式</th>
                                <th lay-data="{field:'Ename',align:'center',width:150 }">英文形式</th>
                                <th lay-data="{field:'imgUrl',align:'center', width:150,templet:'#imgTpl'}">卡通封面</th>
                                <th lay-data="{fixed: 'right', align:'center', toolbar: '#barDemo'}">执行操作</th>                                      
                              </tr>
                            </thead>
                          </table>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>

    <script type="text/html" id="imgTpl">
        <img src="{{d.imgUrl}}">
    </script>
    <!-- 行工具栏删除按钮 -->
    <script type="text/html" id="barDemo">
      <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
      <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </script>
    <script>
      layui.use('table', function(){
        var table = layui.table;
        table.on('tool(videoinfo)',function(obj){
          var data = obj.data; //获得当前行数据
          var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
          if(layEvent==='del'){
            console.log(data)
            layer.open({
              content:'确认删除该条内容吗？删除将失去关于该视频内容的所有信息',
              btn:['确认注销','取消'],
              yes:function(index,layero){
                $.ajax({
                  type:'delete',
                  url:'https://api.lzjlw.top:3030/backstage/fruit_Cognize?cognizeId='+data.cognizeId,
                  success:function(res){
                    location.reload();
                  },
                  complete:function(res){
                    console.log('请求完成');
                  }
                })
              },
              btn2:function(){
                xadmin.father_reload();
              },
              cancle:function(){
                location.reload()
              }
            })
          }else if(layEvent==='edit'){
            console.log(data)
            xadmin.open('更新视频内容','./fruit-edit.html?CognizeId='+data.cognizeId,600,400)
          }
        })  
      });
    </script>
</html>